﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufExtension.h"
#include "ICommandManager.h"

namespace gnuf
{
    template<class Command>
    class GnufExtensionCommandRegisterHelper
    {
    public:
        GnufExtensionCommandRegisterHelper(const std::wstring & moduleName)
        {
            auto pCommand = NEW_AS_OWNER_PTR(Command);
            m_strCmdId = pCommand->GetCommandId();
            gcmp::ICommandManager::Get()->RegisterCommand(moduleName, TransferOwnership(pCommand));
        }
        ~GnufExtensionCommandRegisterHelper()
        {
            gcmp::ICommandManager::Get()->UnRegisterCommand(m_strCmdId);
        }

    private:
        std::wstring m_strCmdId;
    };
}

#define REGISTER_GNUF_EXTENSION_COMMAND(Command) \
namespace gnuf { \
    GnufExtensionCommandRegisterHelper<Command> s_##GnufExtension##Command##RegisterHelper(TR_MODULE_NAME); \
} 
